package com.sbwork.demo.convert;

import com.sbwork.base.convert.BaseConvert;
import com.sbwork.demo.entity.HyProject;
import com.sbwork.demo.form.HyProjectForm;
import com.sbwork.sys.form.SysRegionForm;
import com.sbwork.sys.service.SysRegionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 项目管理entity、form转换类
 */
@Component
public class HyProjectConvert extends BaseConvert<HyProject, HyProjectForm> {

    @Resource
    private SysRegionService sysRegionService;

    @Override
    protected void afterConvertToForm(HyProject entity, HyProjectForm form) {
        if (StringUtils.isNotBlank(entity.getProvince())) {
            SysRegionForm sysRegionForm = sysRegionService.getFormByCode(entity.getProvince());
            if (sysRegionForm != null) {
                form.setProvinceName(sysRegionForm.getAreaName());
            }
        }
        if (StringUtils.isNotBlank(entity.getCity())) {
            SysRegionForm sysRegionForm = sysRegionService.getFormByCode(entity.getCity());
            if (sysRegionForm != null) {
                form.setCityName(sysRegionForm.getAreaName());
            }
        }
        if (StringUtils.isNotBlank(entity.getDistrict())) {
            SysRegionForm sysRegionForm = sysRegionService.getFormByCode(entity.getDistrict());
            if (sysRegionForm != null) {
                form.setDistrictName(sysRegionForm.getAreaName());
            }
        }

    }

    @Override
    protected void afterConvertToEntity(HyProjectForm form, HyProject entity) {

    }
}
